﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>布尔表达式</title>
</head>
<body>
    <script language="javascript" type="text/javaScript">
        function checkYear() {
            let txtYearObj = document.all.txtYear;
            let txtYear = txtYearObj.value;
            if ((txtYear === null) || (txtYear.length < 1) || (txtYear < 0)) {
                window.alert("请在文本框中输入正确的年份");
                txtYearObj.focus();
                return;
            }
            if (isNaN(txtYear)) {
                window.alert("年份必须为整型数字");
                txtYearObj.focus();
                return;
            }
            if (isLeapYear(txtYear)) {
                window.alert(txtYear + "年是闰年");
            } else {
                window.alert(txtYear + "年不是闰年");
            }
        }
        // 判断是否是闰年
        function isLeapYear(yearVal) {
            if ((yearVal % 100 === 0) && (yearVal % 400 === 0)) {
                return true;
            }
            if (yearVal % 4 === 0) {
                return true;
            }
            return false;
        }


    </script>
    <form action="#" name="frmYear">
        请输入当前年份：
        <input type="text" name="txtYear">
        <p>
            请单击按钮以判断是否为闰年：
            <input type="button" value="确定" onclick="checkYear()">
    </form>
</body>
</html>
